package com.google;

import android.app.PendingIntent;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import com.android.vending.billing.IMarketBillingService;
import com.android.vending.billing.IMarketBillingService.Stub;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;

public class BillingService extends Service
  implements ServiceConnection
{
  private static final String TAG = "BillingService";
  private static Boolean configured = Boolean.valueOf(false);
  private static LinkedList<HandleIntentRecord> mPendingHandleIntents;
  private static LinkedList<BillingRequest> mPendingRequests = new LinkedList();
  private static HashMap<Long, BillingRequest> mSentRequests = new HashMap();
  private static IMarketBillingService mService;

  static
  {
    mPendingHandleIntents = new LinkedList();
  }

  private boolean bindToMarketBillingService()
  {
    try
    {
      Log.i("BillingService", "binding to Market billing service");
      if (bindService(new Intent("com.android.vending.billing.MarketBillingService.BIND"), this, 1))
        return true;
      Log.e("BillingService", "Could not bind to service.");
      return false;
    }
    catch (SecurityException localSecurityException)
    {
      while (true)
        Log.e("BillingService", "Security exception: " + localSecurityException);
    }
  }

  private void checkResponseCode(long paramLong, Consts.ResponseCode paramResponseCode)
  {
    BillingRequest localBillingRequest = (BillingRequest)mSentRequests.get(Long.valueOf(paramLong));
    if (localBillingRequest != null)
    {
      Log.d("BillingService", localBillingRequest.getClass().getSimpleName() + ": " + paramResponseCode);
      localBillingRequest.responseCodeReceived(paramResponseCode);
    }
    mSentRequests.remove(Long.valueOf(paramLong));
  }

  private boolean confirmNotifications(int paramInt, String[] paramArrayOfString)
  {
    return new ConfirmNotifications(paramInt, paramArrayOfString).runRequest();
  }

  private boolean getPurchaseInformation(int paramInt, String[] paramArrayOfString)
  {
    return new GetPurchaseInformation(paramInt, paramArrayOfString).runRequest();
  }

  public static boolean isConfigured()
  {
    synchronized (configured)
    {
      boolean bool = configured.booleanValue();
      return bool;
    }
  }

  private void purchaseStateChanged(int paramInt, String paramString1, String paramString2)
  {
    ArrayList localArrayList1 = Security.verifyPurchase(paramString1, paramString2);
    if (localArrayList1 == null);
    ArrayList localArrayList2;
    do
    {
      return;
      localArrayList2 = new ArrayList();
      Iterator localIterator = localArrayList1.iterator();
      while (localIterator.hasNext())
      {
        Security.VerifiedPurchase localVerifiedPurchase = (Security.VerifiedPurchase)localIterator.next();
        if (localVerifiedPurchase.notificationId != null)
          localArrayList2.add(localVerifiedPurchase.notificationId);
        ResponseHandler.purchaseResponse(this, localVerifiedPurchase.purchaseState, localVerifiedPurchase.productId, localVerifiedPurchase.orderId, localVerifiedPurchase.purchaseTime, localVerifiedPurchase.developerPayload);
      }
    }
    while (localArrayList2.isEmpty());
    confirmNotifications(paramInt, (String[])localArrayList2.toArray(new String[localArrayList2.size()]));
  }

  private void runPendingRequests()
  {
    int i = -1;
    while (true)
    {
      BillingRequest localBillingRequest = (BillingRequest)mPendingRequests.peek();
      if (localBillingRequest == null)
        break label52;
      if (!localBillingRequest.runIfConnected())
        break;
      mPendingRequests.remove();
      if (i < localBillingRequest.getStartId())
        i = localBillingRequest.getStartId();
    }
    bindToMarketBillingService();
    label52: 
    while (i < 0)
      return;
    Log.i("BillingService", "stopping service, startId: " + i);
    stopSelf(i);
  }

  public static void setConfigured()
  {
    synchronized (configured)
    {
      configured = Boolean.valueOf(true);
      BillingService localBillingService = new BillingService();
      Iterator localIterator = mPendingHandleIntents.iterator();
      if (localIterator.hasNext())
      {
        HandleIntentRecord localHandleIntentRecord = (HandleIntentRecord)localIterator.next();
        localBillingService.handleCommand(localHandleIntentRecord.getIntent(), localHandleIntentRecord.getStartId());
      }
    }
    mPendingHandleIntents.clear();
  }

  public boolean checkBillingSupported()
  {
    return new CheckBillingSupported().runRequest();
  }

  public void handleCommand(Intent paramIntent, int paramInt)
  {
    if (paramIntent == null)
      Log.i("BillingService", "handleCommand() intent is null");
    String str;
    do
    {
      return;
      str = paramIntent.getAction();
      Log.i("BillingService", "handleCommand() action: " + str);
      if ("com.example.dungeons.CONFIRM_NOTIFICATION".equals(str))
      {
        confirmNotifications(paramInt, paramIntent.getStringArrayExtra("notification_id"));
        return;
      }
      if ("com.example.dungeons.GET_PURCHASE_INFORMATION".equals(str))
      {
        getPurchaseInformation(paramInt, new String[] { paramIntent.getStringExtra("notification_id") });
        return;
      }
      if ("com.android.vending.billing.PURCHASE_STATE_CHANGED".equals(str))
      {
        purchaseStateChanged(paramInt, paramIntent.getStringExtra("inapp_signed_data"), paramIntent.getStringExtra("inapp_signature"));
        return;
      }
    }
    while (!"com.android.vending.billing.RESPONSE_CODE".equals(str));
    checkResponseCode(paramIntent.getLongExtra("request_id", -1L), Consts.ResponseCode.valueOf(paramIntent.getIntExtra("response_code", Consts.ResponseCode.RESULT_ERROR.ordinal())));
  }

  public IBinder onBind(Intent paramIntent)
  {
    return null;
  }

  public void onServiceConnected(ComponentName paramComponentName, IBinder paramIBinder)
  {
    Log.d("BillingService", "Billing service connected");
    mService = IMarketBillingService.Stub.asInterface(paramIBinder);
    runPendingRequests();
  }

  public void onServiceDisconnected(ComponentName paramComponentName)
  {
    Log.w("BillingService", "Billing service disconnected");
    mService = null;
  }

  public void onStart(Intent paramIntent, int paramInt)
  {
    if (isConfigured())
    {
      handleCommand(paramIntent, paramInt);
      return;
    }
    mPendingHandleIntents.add(new HandleIntentRecord(paramIntent, paramInt));
  }

  public boolean requestPurchase(String paramString1, String paramString2)
  {
    return new RequestPurchase(paramString1, paramString2).runRequest();
  }

  public boolean restoreTransactions()
  {
    return new RestoreTransactions().runRequest();
  }

  public void setContext(Context paramContext)
  {
    attachBaseContext(paramContext);
  }

  public void unbind()
  {
    try
    {
      unbindService(this);
      return;
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
    }
  }

  abstract class BillingRequest
  {
    protected long mRequestId;
    private final int mStartId;

    public BillingRequest(int arg2)
    {
      int i;
      this.mStartId = i;
    }

    public int getStartId()
    {
      return this.mStartId;
    }

    protected void logResponseCode(String paramString, Bundle paramBundle)
    {
      Consts.ResponseCode localResponseCode = Consts.ResponseCode.valueOf(paramBundle.getInt("RESPONSE_CODE"));
      Log.e("BillingService", paramString + " received " + localResponseCode.toString());
    }

    protected Bundle makeRequestBundle(String paramString)
    {
      Bundle localBundle = new Bundle();
      localBundle.putString("BILLING_REQUEST", paramString);
      localBundle.putInt("API_VERSION", 1);
      localBundle.putString("PACKAGE_NAME", BillingService.this.getPackageName());
      return localBundle;
    }

    protected void onRemoteException(RemoteException paramRemoteException)
    {
      Log.w("BillingService", "remote billing service crashed");
      BillingService.access$202(null);
    }

    protected void responseCodeReceived(Consts.ResponseCode paramResponseCode)
    {
    }

    protected abstract long run()
      throws RemoteException;

    public boolean runIfConnected()
    {
      Log.d("BillingService", getClass().getSimpleName());
      if (BillingService.mService != null)
        try
        {
          this.mRequestId = run();
          Log.d("BillingService", "request id: " + this.mRequestId);
          if (this.mRequestId >= 0L)
            BillingService.mSentRequests.put(Long.valueOf(this.mRequestId), this);
          return true;
        }
        catch (RemoteException localRemoteException)
        {
          onRemoteException(localRemoteException);
        }
      return false;
    }

    public boolean runRequest()
    {
      if (runIfConnected())
        return true;
      if (BillingService.this.bindToMarketBillingService())
      {
        BillingService.mPendingRequests.add(this);
        return true;
      }
      return false;
    }
  }

  public class CheckBillingSupported extends BillingService.BillingRequest
  {
    public CheckBillingSupported()
    {
      super(-1);
    }

    protected long run()
      throws RemoteException
    {
      Bundle localBundle = makeRequestBundle("CHECK_BILLING_SUPPORTED");
      int i = BillingService.mService.sendBillingRequest(localBundle).getInt("RESPONSE_CODE");
      Log.i("BillingService", "CheckBillingSupported response code: " + Consts.ResponseCode.valueOf(i));
      if (i == Consts.ResponseCode.RESULT_OK.ordinal());
      for (boolean bool = true; ; bool = false)
      {
        ResponseHandler.checkBillingSupportedResponse(bool);
        return Consts.BILLING_RESPONSE_INVALID_REQUEST_ID;
      }
    }
  }

  public class ConfirmNotifications extends BillingService.BillingRequest
  {
    final String[] mNotifyIds;

    public ConfirmNotifications(int paramArrayOfString, String[] arg3)
    {
      super(paramArrayOfString);
      Object localObject;
      this.mNotifyIds = localObject;
    }

    protected long run()
      throws RemoteException
    {
      Bundle localBundle1 = makeRequestBundle("CONFIRM_NOTIFICATIONS");
      localBundle1.putStringArray("NOTIFY_IDS", this.mNotifyIds);
      Bundle localBundle2 = BillingService.mService.sendBillingRequest(localBundle1);
      logResponseCode("confirmNotifications", localBundle2);
      return localBundle2.getLong("REQUEST_ID", Consts.BILLING_RESPONSE_INVALID_REQUEST_ID);
    }
  }

  public class GetPurchaseInformation extends BillingService.BillingRequest
  {
    long mNonce;
    final String[] mNotifyIds;

    public GetPurchaseInformation(int paramArrayOfString, String[] arg3)
    {
      super(paramArrayOfString);
      Object localObject;
      this.mNotifyIds = localObject;
    }

    protected void onRemoteException(RemoteException paramRemoteException)
    {
      super.onRemoteException(paramRemoteException);
      Security.removeNonce(this.mNonce);
    }

    protected long run()
      throws RemoteException
    {
      this.mNonce = Security.generateNonce();
      Bundle localBundle1 = makeRequestBundle("GET_PURCHASE_INFORMATION");
      localBundle1.putLong("NONCE", this.mNonce);
      localBundle1.putStringArray("NOTIFY_IDS", this.mNotifyIds);
      Bundle localBundle2 = BillingService.mService.sendBillingRequest(localBundle1);
      logResponseCode("getPurchaseInformation", localBundle2);
      return localBundle2.getLong("REQUEST_ID", Consts.BILLING_RESPONSE_INVALID_REQUEST_ID);
    }
  }

  private static class HandleIntentRecord
  {
    private Intent intent;
    private int startId;

    public HandleIntentRecord(Intent paramIntent, int paramInt)
    {
      this.intent = paramIntent;
      this.startId = paramInt;
    }

    public Intent getIntent()
    {
      return this.intent;
    }

    public int getStartId()
    {
      return this.startId;
    }
  }

  public class RequestPurchase extends BillingService.BillingRequest
  {
    public final String mDeveloperPayload;
    public final String mProductId;

    public RequestPurchase(String arg2)
    {
      this(str, null);
    }

    public RequestPurchase(String paramString1, String arg3)
    {
      super(-1);
      this.mProductId = paramString1;
      Object localObject;
      this.mDeveloperPayload = localObject;
    }

    protected void responseCodeReceived(Consts.ResponseCode paramResponseCode)
    {
      ResponseHandler.responseCodeReceived(BillingService.this, this, paramResponseCode);
    }

    protected long run()
      throws RemoteException
    {
      Bundle localBundle1 = makeRequestBundle("REQUEST_PURCHASE");
      localBundle1.putString("ITEM_ID", this.mProductId);
      if (this.mDeveloperPayload != null)
        localBundle1.putString("DEVELOPER_PAYLOAD", this.mDeveloperPayload);
      Bundle localBundle2 = BillingService.mService.sendBillingRequest(localBundle1);
      PendingIntent localPendingIntent = (PendingIntent)localBundle2.getParcelable("PURCHASE_INTENT");
      if (localPendingIntent == null)
      {
        Log.e("BillingService", "Error with requestPurchase");
        return Consts.BILLING_RESPONSE_INVALID_REQUEST_ID;
      }
      ResponseHandler.buyPageIntentResponse(localPendingIntent, new Intent());
      return localBundle2.getLong("REQUEST_ID", Consts.BILLING_RESPONSE_INVALID_REQUEST_ID);
    }
  }

  public class RestoreTransactions extends BillingService.BillingRequest
  {
    long mNonce;

    public RestoreTransactions()
    {
      super(-1);
    }

    protected void onRemoteException(RemoteException paramRemoteException)
    {
      super.onRemoteException(paramRemoteException);
      Security.removeNonce(this.mNonce);
    }

    protected void responseCodeReceived(Consts.ResponseCode paramResponseCode)
    {
      ResponseHandler.responseCodeReceived(BillingService.this, this, paramResponseCode);
    }

    protected long run()
      throws RemoteException
    {
      this.mNonce = Security.generateNonce();
      Bundle localBundle1 = makeRequestBundle("RESTORE_TRANSACTIONS");
      localBundle1.putLong("NONCE", this.mNonce);
      Bundle localBundle2 = BillingService.mService.sendBillingRequest(localBundle1);
      logResponseCode("restoreTransactions", localBundle2);
      return localBundle2.getLong("REQUEST_ID", Consts.BILLING_RESPONSE_INVALID_REQUEST_ID);
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.google.BillingService
 * JD-Core Version:    0.6.2
 */